<!DOCTYPE html>
<html ng-app="myApp">
	<head>
		<meta charset="utf-8">
		<title></title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.css">
<script src="js/angular.js"></script>
<script src="js/ui-bootstrap-tpls.js"></script>
<script src="js/angular-locale_zh-cn.js"></script>
<style>
  .full button span {
    background-color: limegreen;
    border-radius: 32px;
    color: black;
  }
  .partially button span {
    background-color: orange;
    border-radius: 32px;
    color: black;
  }
</style>
	</head>
	<body>
	<div ng-controller="DatepickerDemoCtrl">
    <h4> 日期选择</h4>
    <div class="row">
        <div class="col-md-6">
        	<div class="search radius6">
                <form name="searchform" ng-submit="search()">
                    <p class="input-group">
              			<input type="text" class="form-control" style="padding-bottom: 2px;padding-top: 2px;"
              			uib-datepicker-popup="{{format}}" ng-model="dt" is-open="startopened" 
              			min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" 
              			date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" 
              			/>            
              			<span class="input-group-btn">
              				<button type="button" class="btn  btn-danger" id="start" ng-click="clear($event)">X</button>
                			<button type="button" id="startOpen" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
              			</span>
                        <input type="text" class="form-control" 
                        uib-datepicker-popup="{{format}}" ng-model="dt1" is-open="endopened" 
              			min-date="minDate" max-date="maxDate" datepicker-options="dateOptions"
              			date-disabled="disabled(date, mode)"  close-text="Close" 
              			/>
                		<span class="input-group-btn">
              				<button type="button" id="end" class="btn  btn-danger" ng-click="clear($event)">X</button>
                			<button type="button" id="endOpen" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
                		</span>
            		</p>
                    <input class="btn_srh" type="submit" name="submit" value="CallSearch">
                </form>
            </div>
        </div> 
    </div>
    <h4>选择时间格式</h4>
    <div class="row">
        <div class="col-md-6">
            <label>Format:</label> <select class="form-control" ng-model="format" ng-options="f for f in formats"><option></option></select>
        </div>
    </div>
   <hr />
  <!--  <div class="row">
        <div class="col-lg-10">
            <div class="panel-body">
                    <div class="searchContainer">
                        <form name="searchform1" ng-submit="search1()">
                            <div class="col-lg-4 col-md-4 col-sm-12 searchDiv">
                                <label class="col-lg-4 searchLabel">{{'Queues' | translate}}</label>
                                <input class="col-lg-8 search-inp" id="queue">
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-12 searchDiv">
                                <label class="col-lg-4 searchLabel">{{'Agents' | translate }}</label>
                                <input class="col-lg-8 search-inp" id="agent">
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-12 searchDiv">
                                <label class="col-lg-4 searchLabel">{{'Start'| translate }}</label>
                                <p class="input-group ">
                                    <input type="text" class="form-control search-date"
                                        uib-datepicker-popup="{{format}}" ng-model="dt" is-open="startopened"
                                        min-date="minDate" max-date="maxDate" datepicker-options="dateOptions"
                                        date-disabled="disabled(date, mode)" ng-required="true" close-text="Close"
                                     />
                                    <span class="input-group-btn ">
                                    <button type="button" id="startOpen" class="btn btn-default search-dateBtn" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
                                    </span>
                                </p>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-12 searchDiv">
                                <label class="col-lg-4 searchLabel">{{'End'| translate }}</label>
                                <p class="input-group ">
                                    <input type="text" class="form-control search-date"
                                        uib-datepicker-popup="{{format}}" ng-model="dt1" is-open="endopened"
                                        min-date="minDate" max-date="maxDate" datepicker-options="dateOptions"
                                        date-disabled="disabled(date, mode)" ng-required="true" close-text="Close"
                                     />
                                    <span class="input-group-btn ">
                                    <button type="button" id="endOpen" class="btn btn-default search-dateBtn" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
                                    </span>
                                </p>
                            </div>
                            <input class="btn_srh searchBtn" type="submit" name="submit" value="{{'CallSearch' | translate }}">
                        </form>
                    </div>
                </div>
        </div>
    </div>
    -->
 <!--   <hr />
    <button type="button" class="btn btn-sm btn-info" ng-click="today()">Today</button>
    <button type="button" class="btn btn-sm btn-default" ng-click="setDate(2009, 7, 24)">2009-08-24</button>
    <button type="button" class="btn btn-sm btn-default" ng-click="toggleMin()" uib-tooltip="After today restriction">Min date</button>
    -->
</div>
<script>
	angular.module('myApp',['ui.bootstrap']).controller('DatepickerDemoCtrl', function ($scope,$filter) {
  $scope.today = function() {  //创建today方法
    $scope.dt = new Date();
    $scope.dt1= new Date();
  }; 
  $scope.today();//运行today方法
  $scope.search=function(){
   var startdate=$filter('date')($scope.dt,'yyyy-M-d'); 
   var enddate=$filter('date')($scope.dt1,'yyyy-M-d');//在js中使用filter改变时间格式。在html中用{{dt | date:'yyyy-M-d'}}
  	  console.log(startdate);
  	  console.log(enddate);
  };

  $scope.clear = function(event) { //点击clear清空日期
  	var id=event.target.getAttribute("id");     
  	if(id=="start"){
    $scope.dt = null;
   }
  	if(id=="end"){
  		$scope.dt1 = null;
  	}
  };

  // Disable weekend selection
  $scope.disabled = function(date, mode) {
    return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
  };

  $scope.toggleMin = function() {
    $scope.minDate = $scope.minDate ? null : new Date();
  };

  $scope.toggleMin();
  $scope.maxDate = new Date(2020, 5, 22);

  $scope.open = function($event) {
  	var id=$event.target.getAttribute("id");    //用该方法在google浏览器使用时候，偶尔会出现回去不到Id的情况，未解决
  	if(id=="startOpen"){
    $scope.startopened = true;
   }
  	if(id=="endOpen"){
  		$scope.endopened = true;
  	}
  };

  $scope.setDate = function(year, month, day) {
    $scope.dt = new Date(year, month, day);
  };

  $scope.dateOptions = {
    formatYear: 'yy',
    startingDay: 1
  };

  $scope.formats = ['yyyy-M-d','dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
  $scope.format = $scope.formats[0];  //此处input type="text",若type="date"则不行
  //若不想改变日期格式，则可以直接把input中的uib-datepicker-popup="{{format}}"写成uib-datepicker-popup="yyyy-M-d"固定的格式
  var tomorrow = new Date();
  tomorrow.setDate(tomorrow.getDate() + 1);
  var afterTomorrow = new Date();
  afterTomorrow.setDate(tomorrow.getDate() + 2);
  $scope.events =
    [
      {
        date: tomorrow,
        status: 'full'
      },
      {
        date: afterTomorrow,
        status: 'partially'
      }
    ];

  $scope.getDayClass = function(date, mode) {
    if (mode === 'day') {
      var dayToCheck = new Date(date).setHours(0,0,0,0);

      for (var i = 0; i < $scope.events.length; i++) {
        var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);

        if (dayToCheck === currentDay) {
          return $scope.events[i].status;
        }
      }
    }

    return '';
  };
});
</script>
	</body>
</html>
